/**
 * 用水单元
 */
var yueStore4_1 = Ext.create('Ext.data.Store', {
	storeId: 'yueSample4_1',
	fields:[ 'index1', 'index2', 'index3', 'index4', 'index5', 'index6', 'index7', 'index8', 'index9', 'index10',
		'index11', 'index12', 'index13', 'index14', 'index15', 'index16', 'index17', 'index18', 'index19', 'index20',
		'index21'],
	data: [	{index1: '1月'},
			{index1: '2月'},
			{index1: '3月'},
			{index1: '4月'},
			{index1: '5月'},
			{index1: '6月'},
			{index1: '7月'},
			{index1: '8月'},
			{index1: '9月'},
			{index1: '10月'},
			{index1: '11月'},
			{index1: '12月'},
			{index1: '全年'}],
	listeners: {
		datachanged: {
			fn: function(obj, eOpt){
				var size = yueStore4_1.getCount();
				if(yueChartUseWater1 != null){
					var series = yueChartUseWater1.series;
					series[0].setData(getDataArray(obj, 'index3', 0, size));
					series[1].setData(getDataArray(obj, 'index2', 0, size));
				}
				if(yueChartUseWater2 != null){
					var series = yueChartUseWater2.series;
					series[0].setData(getDataArray(obj, 'index7', 0, size));
					series[1].setData(getDataArray(obj, 'index6', 0, size));
				}
				if(yueChartUseWater3 != null){
					var series = yueChartUseWater3.series;
					series[0].setData(getDataArray(obj, 'index11', 0, size));
					series[1].setData(getDataArray(obj, 'index10', 0, size));
				}
				if(yueChartUseWater4 != null){
					var series = yueChartUseWater4.series;
					series[0].setData(getDataArray(obj, 'index15', 0, size));
					series[1].setData(getDataArray(obj, 'index14', 0, size));
				}
				if(yueChartUseWater5 != null){
					var series = yueChartUseWater5.series;
					series[0].setData([yueSumArray(getDataArray(obj, 'index3', 0, size)),
						yueSumArray(getDataArray(obj, 'index7', 0, size)),
						yueSumArray(getDataArray(obj, 'index11', 0, size)),
						yueSumArray(getDataArray(obj, 'index15', 0, size))]);
					series[1].setData([yueSumArray(getDataArray(yueStore4_1, 'index2', 0, size)),
						yueSumArray(getDataArray(obj, 'index6', 0, size)),
						yueSumArray(getDataArray(obj, 'index10', 0, size)),
						yueSumArray(getDataArray(obj, 'index14', 0, size))]);
				}
			}
		}
	}
});

var yueChartUseWater1;
var yueChartUseWater2;
var yueChartUseWater3;
var yueChartUseWater4;
var yueChartUseWater5;



function yueWaterUnitChart(element, title, data1, data2){
	var size = yueStore4_1.getCount();
	var xai = getDataArray(yueStore4_1, 'index1', 0, size);
	return Highcharts.chart(element, {
		title: {
	        text: title
	    },
	    xAxis: {
	        categories: xai
	    },
	    yAxis: {
	        title: {
	            text: '水量 (亿m³)'
	        }
	    },
	    plotOptions: {
	    	spline: {
	    		marker: {
	    			enabled: false
	    		}
	    	}
	    },
	    series: [{
	        type: 'column',
	        name: '供水',
	        data: data1
	    }, {
	        type: 'spline',
	        name: '需水',
	        data: data2,
	        marker: {
	            lineWidth: 2,
	            lineColor: Highcharts.getOptions().colors[3],
	            fillColor: 'white'
	        }
	    }]
	});
}

function yueWaterUnitChart2(element, title, data1, data2){
	return Highcharts.chart(element, {
		title: {
	        text: title
	    },
	    xAxis: {
	        categories: ['农业','工业','生活','生态']
	    },
	    yAxis: {
	        title: {
	            text: '水量 (亿m³)'
	        }
	    },
	    series: [{
	        type: 'column',
	        name: '需水',
	        data: data1
	    }, {
	    	type: 'column',
	        name: '供水',
	        data: data2
	    }]
	});
}

/*function loadyueWaterUnitChart(){
	yueWaterUnitChart('yuept_1', '农业', getDataArray(yueStore4_1, 'index3', 0, 12), getDataArray(yueStore4_1, 'index2', 0, 12));
	yueWaterUnitChart('yuept_2', '工业', getDataArray(yueStore4_1, 'index7', 0, 12), getDataArray(yueStore4_1, 'index6', 0, 12));
	yueWaterUnitChart('yuept_3', '生活', getDataArray(yueStore4_1, 'index11', 0, 12), getDataArray(yueStore4_1, 'index10', 0, 12));
	yueWaterUnitChart('yuept_4', '生态', getDataArray(yueStore4_1, 'index15', 0, 12), getDataArray(yueStore4_1, 'index14', 0, 12));
	yueWaterUnitChart2('yuept_5', '汇总',
		[yueSumArray(getDataArray(yueStore4_1, 'index3', 0, 12)),
			yueSumArray(getDataArray(yueStore4_1, 'index7', 0, 12)),
			yueSumArray(getDataArray(yueStore4_1, 'index11', 0, 12)),
			yueSumArray(getDataArray(yueStore4_1, 'index15', 0, 12))],
		[yueSumArray(getDataArray(yueStore4_1, 'index2', 0, 12)),
			yueSumArray(getDataArray(yueStore4_1, 'index6', 0, 12)),
			yueSumArray(getDataArray(yueStore4_1, 'index10', 0, 12)),
			yueSumArray(getDataArray(yueStore4_1, 'index14', 0, 12))]);
}*/

function yueSumArray(arr){
	var output = 0;
	for(var i=0;i<arr.length;i++){
		output += arr[i];
	}
	return output;
}

function loadyueWaterUnitData2(data){
	yueStore4_1.setData(data);
}

Ext.define('Admin.view.needwater.subpage.useWaterUnit',{
	extend:'Ext.panel.Panel',
	xtype:'yueUseWaterUnit',
	//起别名
	alias:'yueUseWaterUnit',
	require:[],
	user:[],
	userCLs:'big-100 small-100',
	layout: {
        type: 'vbox',
        align: 'stretch'
    },
	items: [{
		xtype: 'grid',
		store: Ext.data.StoreManager.lookup('yueSample4_1'),
		border: true,
		columns: [
			{ text: '月份', dataIndex: 'index1', minWidth: 100, align: 'center' },
			{text: '农业', columns:[
				{ text: '需水', dataIndex: 'index2', minWidth: 100, align: 'center', renderer:
						function customRound(value, record){
							if(value == null)return null;
							return Ext.util.Format.round(value, 3);
						}
				},
				{ text: '供水', dataIndex: 'index3', minWidth: 100, align: 'center', renderer:
						function customRound(value, record){
							if(value == null)return null;
							return Ext.util.Format.round(value, 3);
						}
				},
				{ text: '缺水', dataIndex: 'index4', minWidth: 100, align: 'center', renderer:
						function customRound(value, record){
							if(value == null)return null;
							return Ext.util.Format.round(value, 3);
						}
				},
				{ text: '缺水率', dataIndex: 'index5', minWidth: 100, align: 'center', renderer:
						function customRound(value, record){
							if(value == null)return null;
							return Ext.util.Format.round(value, 3);
						}
				}]},
    		{text: '工业', columns:[
    			{ text: '需水', dataIndex: 'index6', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
    			{ text: '供水', dataIndex: 'index7', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
    			{ text: '缺水', dataIndex: 'index8', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
    			{ text: '缺水率', dataIndex: 'index9', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},]},
    		{text: '生活', columns:[
    			{ text: '需水', dataIndex: 'index10', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
    			{ text: '供水', dataIndex: 'index11', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
    			{ text: '缺水', dataIndex: 'index12', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					},
    			{ text: '缺水率', dataIndex: 'index13', minWidth: 100, align: 'center', renderer:
							function customRound(value, record){
								if(value == null)return null;
								return Ext.util.Format.round(value, 3);
							}
					}]},
    		{text: '生态', columns:[
        		{ text: '需水', dataIndex: 'index14', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						},
        		{ text: '供水', dataIndex: 'index15', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						},
        		{ text: '缺水', dataIndex: 'index16', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						},
        		{ text: '缺水率', dataIndex: 'index17', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						}]},
        	{text: '合计', columns:[
        		{ text: '需水', dataIndex: 'index18', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						},
        		{ text: '供水', dataIndex: 'index19', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						},
        		{ text: '缺水', dataIndex: 'index20', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						},
        		{ text: '缺水率', dataIndex: 'index21', minWidth: 100, align: 'center', renderer:
								function customRound(value, record){
									if(value == null)return null;
									return Ext.util.Format.round(value, 3);
								}
						}]}
		],
		flex: 1
	},{
		xtype: 'panel',
		layout: {
	        type: 'hbox',
	        align: 'stretch'
	    },
	    margin: '10 0 0 0',
		flex: 1,
		items: [{
			html: '<div id="yueChart4-1-1" style="width:100%; height:100%;"></div>',
			flex:1,
			listeners: {
				resize: {
					fn: function(obj, width, height, eOpts){
						yueChartUseWater1.reflow();
					}
				},
				boxready: {
					fn: function(obj, width, height, eOpts){
						var size = yueStore4_1.getCount();
						yueChartUseWater1 = yueWaterUnitChart('yueChart4-1-1', '农业', getDataArray(yueStore4_1, 'index3', 0, size), getDataArray(yueStore4_1, 'index2', 0, size));
					}
				}
			}
		},{
			html: '<div id="yueChart4-1-2" style="width:100%; height:100%;"></div>',
			listeners: {
				resize: {
					fn: function(obj, width, height, eOpts){
						yueChartUseWater2.reflow();
					}
				},
				boxready: {
					fn: function(obj, width, height, eOpts){
						var size = yueStore4_1.getCount();
						yueChartUseWater2 = yueWaterUnitChart('yueChart4-1-2', '工业', getDataArray(yueStore4_1, 'index7', 0, size), getDataArray(yueStore4_1, 'index6', 0, size));
					}
				}
			},
			flex:1
		},{
			html: '<div id="yueChart4-1-3" style="width:100%; height:100%;"></div>',
			listeners: {
				resize: {
					fn: function(obj, width, height, eOpts){
						yueChartUseWater3.reflow();
					}
				},
				boxready: {
					fn: function(obj, width, height, eOpts){
						var size = yueStore4_1.getCount();
						yueChartUseWater3 = yueWaterUnitChart('yueChart4-1-3', '生活', getDataArray(yueStore4_1, 'index11', 0, size), getDataArray(yueStore4_1, 'index10', 0, size));
					}
				}
			},
			flex:1
		},{
			html: '<div id="yueChart4-1-4" style="width:100%; height:100%;"></div>',
			listeners: {
				resize: {
					fn: function(obj, width, height, eOpts){
						yueChartUseWater4.reflow();
					}
				},
				boxready: {
					fn: function(obj, width, height, eOpts){
						var size = yueStore4_1.getCount();
						yueChartUseWater4 = yueWaterUnitChart('yueChart4-1-4', '生态', getDataArray(yueStore4_1, 'index15', 0, size), getDataArray(yueStore4_1, 'index14', 0, size));
					}
				}
			},
			flex:1
		},{
			html: '<div id="yueChart4-1-5" style="width:100%; height:100%;"></div>',
			listeners: {
				resize: {
					fn: function(obj, width, height, eOpts){
						yueChartUseWater5.reflow();
					}
				},
				boxready: {
					fn: function(obj, width, height, eOpts){
						var size = yueStore4_1.getCount();
						yueChartUseWater5 = yueWaterUnitChart2('yueChart4-1-5', '汇总',
								[yueSumArray(getDataArray(yueStore4_1, 'index3', 0, size)),
									yueSumArray(getDataArray(yueStore4_1, 'index7', 0, size)),
									yueSumArray(getDataArray(yueStore4_1, 'index11', 0, size)),
									yueSumArray(getDataArray(yueStore4_1, 'index15', 0, size))],
								[yueSumArray(getDataArray(yueStore4_1, 'index2', 0, size)),
									yueSumArray(getDataArray(yueStore4_1, 'index6', 0, size)),
									yueSumArray(getDataArray(yueStore4_1, 'index10', 0, size)),
									yueSumArray(getDataArray(yueStore4_1, 'index14', 0, size))])
					}
				}
			},
			flex:1
		}]
	}]

});
